﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace TheLoader.classes
{
    public class TheLoaderResults
    {
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public int TotalUrlsTested { get; set; }
        public int TotalUrlsBrowsed { get; set; }
        public int NumberOfTests { get; set; }
        public int NumberOfUsers { get; set; }
        public Collection<string> URLCollection { get; set; }
        public Collection<TheLoaderTest> TestsCollection { get; set; }
        public double OverallPageLoadAverage { get; set; }
        public double OverallPagesPerSecond { get; set; }

        public string GetHtml()
        {

            StringBuilder sb = new StringBuilder();
            sb.Append("<html >");
            sb.Append("<head>");
            sb.Append("    <title>The Loader Test Results</title>");
            sb.Append("    <style>");
            sb.Append("        body ");
            sb.Append("        {");
            sb.Append("            BACKGROUND-COLOR: white;");
            sb.Append("            font: verdana;");
            sb.Append("            FONT-FAMILY: Verdana, Helvetica, sans-serif;");
            sb.Append("            FONT-SIZE: 9pt;");
             sb.Append("           FONT-WEIGHT: normal;");
            sb.Append("            LETTER-SPACING: normal;");
            sb.Append("            TEXT-TRANSFORM: none;");
            sb.Append("            WORD-SPACING: normal");
            sb.Append("        }");

            sb.Append("        H1, H2, H3, H4, H5, TH, THEAD, TFOOT");
            sb.Append("        {");
            sb.Append("            COLOR: #003366;");
            sb.Append("        }");
            sb.Append("        h1	{	");
	        sb.Append("            font-family: Verdana, Arial, Helvetica, sans-serif;");
	        sb.Append("            font-size:	2em;");
	        sb.Append("            font-weight:	700;");
	        sb.Append("            font-style:	normal;");
	        sb.Append("            text-decoration:	none;");
	        sb.Append("            word-spacing:	normal;");
	        sb.Append("            letter-spacing:	normal;");
	        sb.Append("            text-transform:	none;");
	        sb.Append("            }	");
        		
            sb.Append("        h2	{	");
	        sb.Append("           font-family: Verdana, Arial, Helvetica, sans-serif;");
	        sb.Append("            font-size:	1.75em;");
	        sb.Append("            font-weight:	700;");
	        sb.Append("            font-style:	normal;");
	        sb.Append("            text-decoration:	none;");
	        sb.Append("            word-spacing:	normal;");
	        sb.Append("            letter-spacing:	normal;");
	        sb.Append("            text-transform:	none;");
	        sb.Append("            }	");
        		
            sb.Append("        h3	{	");
	        sb.Append("            font-family: Verdana, Arial, Helvetica, sans-serif;");
	        sb.Append("            font-size:	1.58em;");
	        sb.Append("            font-weight:	bold;");
	        sb.Append("            font-style:	normal;");
	        sb.Append("            text-decoration:	none;");
	        sb.Append("            word-spacing:	normal;");
	        sb.Append("            letter-spacing:	normal;");
	        sb.Append("            text-transform:	none;");
	        sb.Append("            }	");
        		
            sb.Append("        h4	{	");
	        sb.Append("            font-family: Verdana, Arial, Helvetica, sans-serif;");
	        sb.Append("            font-size:	1.33em;");
	        sb.Append("            font-weight: bold;");
	        sb.Append("            text-decoration:	none;");
	        sb.Append("            word-spacing:	normal;");
	        sb.Append("           letter-spacing:	normal;");
	        sb.Append("            text-transform:	none;");
	        sb.Append("            }	");
        		
            sb.Append("        h5, DT	{	");
	        sb.Append("            font-family: Verdana, Arial, Helvetica, sans-serif;");
	        sb.Append("            font-size:	12pt;");
	        sb.Append("            font-weight:	700;");
	        sb.Append("            font-style:	normal;");
	        sb.Append("            text-decoration:	none;");
	        sb.Append("            word-spacing:	normal;");
	        sb.Append("            letter-spacing:	normal;");
	        sb.Append("            text-transform:	none;");
	        sb.Append("            }	");
        		
            sb.Append("        h6	{	");
	        sb.Append("            font-family: Verdana, Arial, Helvetica, sans-serif;");
	        sb.Append("            font: Verdana;");
	        sb.Append("            font-size:10pt;");
	        sb.Append("            font-weight:normal;");
	        sb.Append("            font-style:	normal;");
	        sb.Append("            text-decoration:	none;");
	        sb.Append("            word-spacing:	normal;");
	        sb.Append("            letter-spacing:	normal;");
	        sb.Append("            text-transform:	none;");
	        sb.Append("            }	");

            sb.Append("        TFOOT, THEAD	{	");
	        sb.Append("            font-size:	1em;");
	        sb.Append("            word-spacing:	normal;");
	        sb.Append("            letter-spacing:	normal;");
	        sb.Append("            text-transform:	none;");
	        sb.Append("            font-family: Arial, Helvetica, sans-serif;");
	        sb.Append("            }	");
        		
            sb.Append("        TH	{	");
	        sb.Append("            vertical-align:	baseline;");
	        sb.Append("            font-size:	1em;");
	        sb.Append("            font-weight:	bold;");
	        sb.Append("            word-spacing:	normal;");
	        sb.Append("            letter-spacing:	normal;");
	        sb.Append("            text-transform:	none;");
	        sb.Append("            font-family: Arial, Helvetica, sans-serif;");
	        sb.Append("            }	");

            sb.Append("        A:link	{	");
	        sb.Append("            text-decoration:	none;");
	        sb.Append("            color:	#3333cc;");
	        sb.Append("            }	");
        		
            sb.Append("        A:visited	{	");
	        sb.Append("            text-decoration:	none;");
	        sb.Append("            color:	#333399;");
	        sb.Append("            }	");
        		
            sb.Append("        A:active	{	");
	        sb.Append("            text-decoration:	none;");
	        sb.Append("            color:	#333399;");
	        sb.Append("            }	");
        		
            sb.Append("        A:hover	{	");
	        sb.Append("            text-decoration:	underline;");
	        sb.Append("            color:	#3333cc;");
	        sb.Append("            }");

            sb.Append("        SMALL	{	");
	        sb.Append("            font-size:	.7em;");
	        sb.Append("            }	");

            sb.Append("        BIG	{	");
	        sb.Append("            font-size:	1.17em;");
	        sb.Append("            }	");

             sb.Append("       BLOCKQUOTE, PRE	{	");
	        sb.Append("            font-family:	Courier New, monospace;");
	        sb.Append("            }	");
        	

            sb.Append("        UL LI	{	");
	        sb.Append("            list-style-type:	square ;");
	        sb.Append("            }	");

            sb.Append("        UL LI LI	{");	
	        sb.Append("            list-style-type:	disc;");
	        sb.Append("            }	");

            sb.Append("        UL LI LI LI	{	");
	        sb.Append("            list-style-type:	circle;");
	        sb.Append("            }	");
        	
            sb.Append("        OL LI	{	");
	        sb.Append("            list-style-type:	decimal;");
	        sb.Append("            }	");

            sb.Append("        OL OL LI	{	");
	        sb.Append("            list-style-type:	lower-alpha;");
	        sb.Append("            }	");

            sb.Append("        OL OL OL LI	{	");
	        sb.Append("            list-style-type:	lower-roman;");
	        sb.Append("            }");	
            sb.Append("    </style>");
            sb.Append("</head>");
            sb.Append("<body>");
            sb.Append("    <div id=\"heading\">");
            sb.Append("        <div align=\"center\">");
            sb.Append("            <h4>The Loader Test Results</h4>");
            sb.Append("        </div>");
           
            sb.Append("    </div>");
            sb.Append("    <div id=\"configuration\">");
            sb.Append("        <h5>Configuration</h5>");
            sb.Append(GetConfigTable());
            sb.Append("    </div>");
            sb.Append("    <div id=\"summary\">");
            sb.Append("        <h5>Overall Summary</h5>");
            sb.Append(GetSummaryTable());
            sb.Append("    </div>");
            sb.Append("    <div id=\"details\">");
            sb.Append("        <h5>Individual Test Details</h5>");
            sb.Append(GetTestsTable());
            sb.Append("    </div>");

            sb.Append("</body>");
            sb.Append("</html>");

            return sb.ToString();

        }

        public string GetTestsTable()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">");
            sb.Append("<tr><th>Test Name</th><th>StartTime</th><th>EndTime</th><th>Avg. Page Time</th></tr>");
            foreach (TheLoaderTest test in TestsCollection)
            {
                sb.Append("<tr><td align=\"center\">"+test.TestID+"</td>");
                sb.Append("<td align=\"center\">" + test.bge.StartTime + "</td>");
                sb.Append("<td align=\"center\">" + test.bge.EndTime + "</td>");
                
                sb.Append("<td align=\"center\">" + test.bge.AveragePageTime + " Seconds</td></tr>");
            }
            sb.Append("</table>");
            return sb.ToString();
        }

        public string GetSummaryTable()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">");
            sb.Append("<tr><th>Start Time</th><th>End Time</th><th>Total Time</th><th>Total URLs Loaded</th><th>Overall Page Load Avg.</th><th>Overall Pages/Second</th></tr>");
           
                sb.Append("<tr><td align=\"center\">" + this.StartTime + "</td>");
                sb.Append("<td align=\"center\">" + this.EndTime + "</td>");
                TimeSpan ts = this.EndTime.Subtract(this.StartTime);
                sb.Append("<td align=\"center\">" + ts.ToString() + "</td>");
                sb.Append("<td align=\"center\">" + this.TotalUrlsBrowsed + "</td>");
                sb.Append("<td align=\"center\">" + this.OverallPageLoadAverage + "</td>");
                sb.Append("<td align=\"center\">" + this.OverallPagesPerSecond + "</td></tr>");
            
            sb.Append("</table>");
            return sb.ToString();
        }

        public string GetConfigTable()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">");
            sb.Append("<tr><th>Number of Tests</th><th>Number of Users</th><th>Number of Urls</th></tr>");

            sb.Append("<tr><td align=\"center\">" + this.NumberOfTests + "</td>");
            sb.Append("<td align=\"center\">" + this.NumberOfUsers + "</td>");
            sb.Append("<td align=\"center\">" + this.URLCollection.Count + "</td></tr>");



            sb.Append("</table>");
            return sb.ToString();
        }
    }
}
